#include "color.h"

void color_getFromRGB(Color4 *cl, u32 col)
{
    cl->r = ((col >> 16) & 0xff) / 255.0f;
    cl->g = ((col >> 8) & 0xff) / 255.0f;
    cl->b = (col & 0xff) / 255.0f;
}

void color_getFromA(Color4 *cl, u32 col)
{
    cl->a = (col & 0xff) / 255.0f;
}

void color_initFromArr(Color4 *cl, float in[4])
{
    cl->r = in[0];
    cl->g = in[1];
    cl->b = in[2];
    cl->a = in[3];
}

void color_initFromRGBA(Color4 *cl, float r, float g, float b, float a)
{
    cl->r = r;
    cl->g = g;
    cl->b = b;
    cl->a = a;
}

Color4 color_multiply(Color4 c1, Color4 c2)
{
    Color4 c;
    color_initFromRGBA(&c, c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a);
    return c;
}

Color4 color_multiplybyflt(Color4 cl, float f)
{
    Color4 c;
    color_initFromRGBA(&c, cl.r * f, cl.g * f, cl.b * f, cl.a * f);
    return c;
}

Color4 color_add(Color4 c1, Color4 c2)
{
    Color4 c;
    color_initFromRGBA(&c, c1.r + c2.r, c1.g + c2.g, c1.b + c2.b, c1.a + c2.a);
    return c;
}

